package com.yixing.tech.wcs.controller;

import com.yixing.tech.common.base.BaseControl;
import com.yixing.tech.common.base.BaseResponse;
import com.yixing.tech.common.base.Rs;
import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.wcs.domain.po.Area;
import com.yixing.tech.wcs.domain.po.PodInteraction;
import com.yixing.tech.wcs.domain.vo.AreaMapping;
import com.yixing.tech.wcs.service.ICRUDService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping(value = "/tbea/ic/wcs/crud")
@Slf4j
public class CRUDController extends BaseControl {

    @Resource
    ICRUDService crudService;


    @PostMapping("/queryAreaMapping")
    public Rs<Object> queryAreaMapping(@RequestBody AreaMapping areaMapping) throws BusinessException {
        log.info("queryAreaMapping=======================================");
        log.info("请求参数:{}", areaMapping);
        return Rs.ok(crudService.queryAreaMapping(areaMapping.getRuleName(), areaMapping.getStartAreaCode(), areaMapping.getEndAreaCode()),
                "查询成功");
    }

    @PostMapping("/queryAreaByCode/{code}")
    public Rs<Object> queryAreaByCode(@PathVariable String code) throws BusinessException {
        log.info("queryAreaByCode=======================================");
        log.info("请求参数:{}", code);
        Area area = crudService.queryAreaByCode(code);
        return Rs.ok(area, "查询成功");
    }

    @PostMapping("/listPodInteraction")
    public Rs<Object> listPodInteraction() throws BusinessException {
        List<PodInteraction> podInteractions = crudService.listPodInteraction();
        return Rs.ok(podInteractions, "查询成功");
    }
}
